import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.android.R;

public class BaseApplication extends Application {
        //activity的count数
        private int Count = 0;
        //是否在前台
        private boolean yon ;

    public void OneLastTime() {

            registerActivityLifecycleCallbacks (new ActivityLifecycleCallbacks () {
                @Override
                public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {

                }

                @Override
                public void onActivityStarted(@NonNull Activity activity) {
                    Activity activity1 = activity;
                    Count ++;
                    if (yon == false) {

                        Toast.makeText(activity1, "欢迎回来", Toast.LENGTH_SHORT).show();
                        yon = true;
                    }

                }

                @Override
                public void onActivityResumed(@NonNull Activity activity) {


                }

                @Override
                public void onActivityPaused(@NonNull Activity activity) {

                }

                @Override
                public void onActivityStopped(@NonNull Activity activity) {
                    Count--;
                    if(Count == 0){
                        yon = false;        }
                }

                @Override
                public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

                }

                @Override
                public void onActivityDestroyed(@NonNull Activity activity) {

                }
            });
        }

}
